

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
  "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">


<html xmlns="http://www.w3.org/1999/xhtml">
  <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    
    <title>ccqw.degreesWidget &mdash; CCQW 0.1.1 documentation</title>
    
    <link rel="stylesheet" href="../../_static/default.css" type="text/css" />
    <link rel="stylesheet" href="../../_static/pygments.css" type="text/css" />
    
    <script type="text/javascript">
      var DOCUMENTATION_OPTIONS = {
        URL_ROOT:    '../../',
        VERSION:     '0.1.1',
        COLLAPSE_INDEX: false,
        FILE_SUFFIX: '.html',
        HAS_SOURCE:  true
      };
    </script>
    <script type="text/javascript" src="../../_static/jquery.js"></script>
    <script type="text/javascript" src="../../_static/underscore.js"></script>
    <script type="text/javascript" src="../../_static/doctools.js"></script>
    <script type="text/javascript" src="../../_static/sidebar.js"></script>
    <link rel="top" title="CCQW 0.1.1 documentation" href="../../index.html" />
    <link rel="up" title="Module code" href="../index.html" /> 
  </head>
  <body>
    <div class="related">
      <h3>Navigation</h3>
      <ul>
        <li class="right" style="margin-right: 10px">
          <a href="../../genindex.html" title="General Index"
             accesskey="I">index</a></li>
        <li class="right" >
          <a href="../../py-modindex.html" title="Python Module Index"
             >modules</a> |</li>
        <li><a href="../../index.html">CCQW 0.1.1 documentation</a> &raquo;</li>
          <li><a href="../index.html" accesskey="U">Module code</a> &raquo;</li> 
      </ul>
    </div>  

    <div class="document">
      <div class="documentwrapper">
        <div class="bodywrapper">
          <div class="body">
            
  <h1>Source code for ccqw.degreesWidget</h1><div class="highlight"><pre>
<span class="c"># -*- coding: utf-8 -*-</span>
<span class="sd">&quot;&quot;&quot; A Degrees Widget module to handles different representations</span>

<span class="sd">      * Degrees.decimals,</span>
<span class="sd">      * Degrees Minutes.decimals,</span>
<span class="sd">      * Degrees, Minutes, Seconds.decimals</span>

<span class="sd">    :Author:</span>
<span class="sd">      - 20111202-20120214 Roberto Vidmar</span>

<span class="sd">    :Revision:  $Revision: 52 $</span>
<span class="sd">                $Date: 2012-11-12 10:07:15 +0100 (Mon, 12 Nov 2012) $</span>

<span class="sd">    :Copyright: 2011-2012</span>
<span class="sd">                Nicola Creati &lt;ncreati@inogs.it&gt;</span>
<span class="sd">                Roberto Vidmar &lt;rvidmar@inogs.it&gt;</span>

<span class="sd">    :License: MIT/X11 License (see :download:`license.txt</span>
<span class="sd">                               &lt;../../license.txt&gt;`)</span>
<span class="sd">&quot;&quot;&quot;</span>

<span class="kn">from</span> <span class="nn">qtCompat</span> <span class="kn">import</span> <span class="n">QtCore</span><span class="p">,</span> <span class="n">Qt</span><span class="p">,</span> <span class="n">Signal</span><span class="p">,</span> <span class="n">QtGui</span>

<span class="n">QCA</span> <span class="o">=</span> <span class="n">QtCore</span><span class="o">.</span><span class="n">QCoreApplication</span>
<span class="kn">from</span> <span class="nn">degrees</span> <span class="kn">import</span> <span class="n">deg2dms</span><span class="p">,</span> <span class="n">deg2dm</span><span class="p">,</span> <span class="n">dms2deg</span>

<span class="c">#===============================================================================</span>
<div class="viewcode-block" id="DValidator"><a class="viewcode-back" href="../../ccqw.html#ccqw.degreesWidget.DValidator">[docs]</a><span class="k">class</span> <span class="nc">DValidator</span><span class="p">(</span><span class="n">QtGui</span><span class="o">.</span><span class="n">QRegExpValidator</span><span class="p">):</span>
  <span class="sd">&quot;&quot;&quot; A validator for Degrees in formats defined by regular Expression</span>
<span class="sd">  &quot;&quot;&quot;</span>
<div class="viewcode-block" id="DValidator.__init__"><a class="viewcode-back" href="../../ccqw.html#ccqw.degreesWidget.DValidator.__init__">[docs]</a>  <span class="k">def</span> <span class="nf">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">parent</span><span class="p">,</span> <span class="n">regexp</span><span class="p">):</span>
    <span class="sd">&quot;&quot;&quot; Create a new instance of the validator.</span>

<span class="sd">     .. note:: parent `AND` regexp must be supplied.</span>

<span class="sd">    :param parent: parent widget</span>
<span class="sd">    :type parent: QtGui widget</span>
<span class="sd">    :param regexp: regular expression that will be used for validation.</span>
<span class="sd">    :type regexp: QtCore.QRegExp</span>
<span class="sd">    :raises:</span>
<span class="sd">    &quot;&quot;&quot;</span>
    <span class="n">qregexp</span> <span class="o">=</span> <span class="n">QtCore</span><span class="o">.</span><span class="n">QRegExp</span><span class="p">(</span><span class="n">regexp</span><span class="p">)</span>
    <span class="nb">super</span><span class="p">(</span><span class="n">DValidator</span><span class="p">,</span> <span class="bp">self</span><span class="p">)</span><span class="o">.</span><span class="n">__init__</span><span class="p">(</span><span class="n">qregexp</span><span class="p">,</span> <span class="n">parent</span><span class="p">)</span>

<span class="c">#===============================================================================</span></div></div>
<div class="viewcode-block" id="AbstractDEditor"><a class="viewcode-back" href="../../ccqw.html#ccqw.degreesWidget.AbstractDEditor">[docs]</a><span class="k">class</span> <span class="nc">AbstractDEditor</span><span class="p">(</span><span class="n">QtGui</span><span class="o">.</span><span class="n">QLineEdit</span><span class="p">):</span>
  <span class="sd">&quot;&quot;&quot; Abstract Line Editor class for degrees handling</span>
<span class="sd">  &quot;&quot;&quot;</span>
<div class="viewcode-block" id="AbstractDEditor.__init__"><a class="viewcode-back" href="../../ccqw.html#ccqw.degreesWidget.AbstractDEditor.__init__">[docs]</a>  <span class="k">def</span> <span class="nf">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">parent</span><span class="p">):</span>
    <span class="sd">&quot;&quot;&quot; Create a new instance of the editor.</span>

<span class="sd">     .. note:: This class should not be used without subclassing.</span>

<span class="sd">    :param parent: parent widget</span>
<span class="sd">    :type parent: QtGui widget</span>
<span class="sd">    :raises:</span>
<span class="sd">    &quot;&quot;&quot;</span>
    <span class="nb">super</span><span class="p">(</span><span class="n">AbstractDEditor</span><span class="p">,</span> <span class="bp">self</span><span class="p">)</span><span class="o">.</span><span class="n">__init__</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">defaultValue</span><span class="p">,</span> <span class="n">parent</span><span class="p">)</span>

    <span class="bp">self</span><span class="o">.</span><span class="n">dWidget</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">parent</span><span class="p">()</span>

    <span class="c">#font = QtGui.QFont(&quot;Monospace&quot;, 12, QtGui.QFont.Bold)</span>
    <span class="n">font</span> <span class="o">=</span> <span class="n">QtGui</span><span class="o">.</span><span class="n">QFont</span><span class="p">(</span><span class="s">&quot;Courier New&quot;</span><span class="p">,</span> <span class="mi">12</span><span class="p">,</span> <span class="n">QtGui</span><span class="o">.</span><span class="n">QFont</span><span class="o">.</span><span class="n">Bold</span><span class="p">)</span>
    <span class="n">font</span><span class="o">.</span><span class="n">setLetterSpacing</span><span class="p">(</span><span class="n">QtGui</span><span class="o">.</span><span class="n">QFont</span><span class="o">.</span><span class="n">AbsoluteSpacing</span><span class="p">,</span> <span class="o">-</span><span class="mf">0.5</span><span class="p">)</span>
    <span class="bp">self</span><span class="o">.</span><span class="n">setFont</span><span class="p">(</span><span class="n">font</span><span class="p">)</span>

    <span class="c"># Set Validator</span>
    <span class="n">validator</span> <span class="o">=</span> <span class="n">DValidator</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">regexp</span><span class="p">)</span>
    <span class="bp">self</span><span class="o">.</span><span class="n">setValidator</span><span class="p">(</span><span class="n">validator</span><span class="p">)</span>
    <span class="c"># Set Input Mask (needed to activate overwrite mode)</span>
    <span class="n">inputMask</span> <span class="o">=</span> <span class="p">(</span><span class="s">&quot;x&quot;</span><span class="p">)</span> <span class="o">*</span> <span class="nb">len</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">defaultValue</span><span class="p">)</span>
    <span class="bp">self</span><span class="o">.</span><span class="n">setInputMask</span><span class="p">(</span><span class="n">inputMask</span><span class="p">)</span>

    <span class="c"># Set line editor width in number of characters</span>
    <span class="n">fm</span> <span class="o">=</span> <span class="n">QtGui</span><span class="o">.</span><span class="n">QFontMetrics</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">font</span><span class="p">())</span>
    <span class="n">width</span> <span class="o">=</span> <span class="n">fm</span><span class="o">.</span><span class="n">width</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">inputMask</span><span class="p">())</span>
    <span class="bp">self</span><span class="o">.</span><span class="n">setMinimumWidth</span><span class="p">(</span><span class="n">width</span><span class="p">)</span>
    <span class="bp">self</span><span class="o">.</span><span class="n">setMaximumWidth</span><span class="p">(</span><span class="n">width</span><span class="p">)</span>
    <span class="bp">self</span><span class="o">.</span><span class="n">setAlignment</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">dWidget</span><span class="o">.</span><span class="n">align</span><span class="p">)</span>
</div>
<div class="viewcode-block" id="AbstractDEditor.signAndText"><a class="viewcode-back" href="../../ccqw.html#ccqw.degreesWidget.AbstractDEditor.signAndText">[docs]</a>  <span class="k">def</span> <span class="nf">signAndText</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
    <span class="sd">&quot;&quot;&quot; Return sign and text of this QLineEdit</span>

<span class="sd">    :returns: sign and text of this QLineEdit</span>
<span class="sd">    :rtype: tuple</span>
<span class="sd">    :raises:</span>
<span class="sd">    &quot;&quot;&quot;</span>
    <span class="n">t</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">text</span><span class="p">()</span>
    <span class="k">if</span> <span class="n">t</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span> <span class="o">==</span> <span class="bp">self</span><span class="o">.</span><span class="n">dWidget</span><span class="o">.</span><span class="n">signschr</span><span class="p">[</span><span class="mi">0</span><span class="p">]:</span>
      <span class="k">return</span> <span class="s">&#39;+&#39;</span><span class="p">,</span> <span class="n">t</span>
    <span class="k">else</span><span class="p">:</span>
      <span class="k">return</span> <span class="s">&#39;-&#39;</span><span class="p">,</span> <span class="n">t</span>
</div>
<div class="viewcode-block" id="AbstractDEditor.fvalue"><a class="viewcode-back" href="../../ccqw.html#ccqw.degreesWidget.AbstractDEditor.fvalue">[docs]</a>  <span class="k">def</span> <span class="nf">fvalue</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
    <span class="sd">&quot;&quot;&quot; Return floating point list of values</span>

<span class="sd">    :returns: floating point value</span>
<span class="sd">    :rtype: float</span>
<span class="sd">    :raises:</span>
<span class="sd">    &quot;&quot;&quot;</span>
    <span class="k">return</span> <span class="p">[</span><span class="nb">float</span><span class="p">(</span><span class="n">v</span><span class="p">)</span> <span class="k">for</span> <span class="n">v</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">value</span><span class="p">()]</span>
</div>
<div class="viewcode-block" id="AbstractDEditor.svalue"><a class="viewcode-back" href="../../ccqw.html#ccqw.degreesWidget.AbstractDEditor.svalue">[docs]</a>  <span class="k">def</span> <span class="nf">svalue</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
    <span class="sd">&quot;&quot;&quot; Return widget text</span>

<span class="sd">    :returns: text content</span>
<span class="sd">    :rtype: string</span>
<span class="sd">    :raises:</span>
<span class="sd">    &quot;&quot;&quot;</span>
    <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">text</span><span class="p">()</span>
</div>
<div class="viewcode-block" id="AbstractDEditor.setValue"><a class="viewcode-back" href="../../ccqw.html#ccqw.degreesWidget.AbstractDEditor.setValue">[docs]</a>  <span class="k">def</span> <span class="nf">setValue</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">value</span><span class="p">):</span>
    <span class="sd">&quot;&quot;&quot; Set Editor value</span>

<span class="sd">    :param value: value to set</span>
<span class="sd">    :type value: string, int or float</span>
<span class="sd">    :raises:</span>
<span class="sd">    &quot;&quot;&quot;</span>
    <span class="bp">self</span><span class="o">.</span><span class="n">setText</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">asString</span><span class="p">(</span><span class="n">value</span><span class="p">))</span>
<span class="c">#===============================================================================</span></div></div>
<div class="viewcode-block" id="DEditor"><a class="viewcode-back" href="../../ccqw.html#ccqw.degreesWidget.DEditor">[docs]</a><span class="k">class</span> <span class="nc">DEditor</span><span class="p">(</span><span class="n">AbstractDEditor</span><span class="p">):</span>
  <span class="sd">&quot;&quot;&quot; Degrees Line Editor</span>

<span class="sd">      Will contain float numbers (degrees) with the format **[+-]ddd.ddddddddd**</span>
<span class="sd">  &quot;&quot;&quot;</span>
<div class="viewcode-block" id="DEditor.__init__"><a class="viewcode-back" href="../../ccqw.html#ccqw.degreesWidget.DEditor.__init__">[docs]</a>  <span class="k">def</span> <span class="nf">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">parent</span><span class="p">):</span>
    <span class="sd">&quot;&quot;&quot; Create a new instance of the editor.</span>

<span class="sd">    :param parent: parent widget</span>
<span class="sd">    :type parent: QtGui widget</span>
<span class="sd">    :raises:</span>
<span class="sd">    &quot;&quot;&quot;</span>
    <span class="k">if</span> <span class="n">parent</span><span class="o">.</span><span class="n">latitude</span><span class="p">:</span>
      <span class="bp">self</span><span class="o">.</span><span class="n">regexp</span> <span class="o">=</span> <span class="p">(</span><span class="s">u&quot;[</span><span class="si">%s</span><span class="s">]([0-8][0-9]\.\d{9}[°]|90\.0{9}[°])&quot;</span> <span class="o">%</span>
        <span class="n">parent</span><span class="o">.</span><span class="n">signschr</span><span class="p">)</span>
    <span class="k">else</span><span class="p">:</span>
      <span class="bp">self</span><span class="o">.</span><span class="n">regexp</span> <span class="o">=</span> <span class="p">(</span><span class="s">u&quot;[</span><span class="si">%s</span><span class="s">]((0\d\d|1[0-7]\d)\.\d{9}[°]|180.0{9}[°])&quot;</span> <span class="o">%</span>
        <span class="n">parent</span><span class="o">.</span><span class="n">signschr</span><span class="p">)</span>

    <span class="bp">self</span><span class="o">.</span><span class="n">fmt</span> <span class="o">=</span> <span class="s">&quot;</span><span class="si">%%</span><span class="s">s</span><span class="si">%%</span><span class="s">0</span><span class="si">%d</span><span class="s">.</span><span class="si">%d</span><span class="s">f</span><span class="si">%s</span><span class="s">&quot;</span> <span class="o">%</span> <span class="p">(</span><span class="n">parent</span><span class="o">.</span><span class="n">degreesLen</span> <span class="o">+</span> <span class="mi">1</span> <span class="o">+</span> <span class="n">parent</span><span class="o">.</span><span class="n">ddecimals</span><span class="p">,</span>
      <span class="n">parent</span><span class="o">.</span><span class="n">ddecimals</span><span class="p">,</span> <span class="n">parent</span><span class="o">.</span><span class="n">degchr</span><span class="p">)</span>

    <span class="bp">self</span><span class="o">.</span><span class="n">defaultValue</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">fmt</span> <span class="o">%</span> <span class="p">(</span><span class="n">parent</span><span class="o">.</span><span class="n">signschr</span><span class="p">[</span><span class="mi">0</span><span class="p">],</span> <span class="mf">0.</span><span class="p">)</span>
    <span class="nb">super</span><span class="p">(</span><span class="n">DEditor</span><span class="p">,</span> <span class="bp">self</span><span class="p">)</span><span class="o">.</span><span class="n">__init__</span><span class="p">(</span><span class="n">parent</span><span class="p">)</span>
</div>
<div class="viewcode-block" id="DEditor.value"><a class="viewcode-back" href="../../ccqw.html#ccqw.degreesWidget.DEditor.value">[docs]</a>  <span class="k">def</span> <span class="nf">value</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
    <span class="sd">&quot;&quot;&quot; Return signed widget string value</span>

<span class="sd">    :returns: signed widget string value</span>
<span class="sd">    :rtype: string</span>
<span class="sd">    :raises:</span>
<span class="sd">    &quot;&quot;&quot;</span>
    <span class="n">sign</span><span class="p">,</span> <span class="n">t</span> <span class="o">=</span> <span class="nb">super</span><span class="p">(</span><span class="n">DEditor</span><span class="p">,</span> <span class="bp">self</span><span class="p">)</span><span class="o">.</span><span class="n">signAndText</span><span class="p">()</span>
    <span class="n">dd</span> <span class="o">=</span> <span class="nb">str</span><span class="p">(</span><span class="n">t</span><span class="p">[</span><span class="mi">1</span><span class="p">:</span><span class="o">-</span><span class="mi">1</span><span class="p">])</span>
    <span class="k">return</span> <span class="p">(</span><span class="n">sign</span> <span class="o">+</span> <span class="n">dd</span><span class="p">,</span> <span class="p">)</span>
</div>
<div class="viewcode-block" id="DEditor.asString"><a class="viewcode-back" href="../../ccqw.html#ccqw.degreesWidget.DEditor.asString">[docs]</a>  <span class="k">def</span> <span class="nf">asString</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">value</span><span class="p">):</span>
    <span class="sd">&quot;&quot;&quot; Return value as formatted string</span>

<span class="sd">        Format is embedded into class.</span>

<span class="sd">    :param value: numerical value</span>
<span class="sd">    :type value: float or int</span>
<span class="sd">    :returns: `value` as formatted string</span>
<span class="sd">    :rtype: string</span>
<span class="sd">    :raises:</span>
<span class="sd">    &quot;&quot;&quot;</span>
    <span class="k">if</span> <span class="n">value</span> <span class="o">&lt;</span> <span class="mi">0</span><span class="p">:</span>
      <span class="n">signchr</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">dWidget</span><span class="o">.</span><span class="n">signschr</span><span class="p">[</span><span class="mi">1</span><span class="p">]</span>
    <span class="k">else</span><span class="p">:</span>
      <span class="n">signchr</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">dWidget</span><span class="o">.</span><span class="n">signschr</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span>
    <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">fmt</span> <span class="o">%</span> <span class="p">(</span><span class="n">signchr</span><span class="p">,</span> <span class="nb">abs</span><span class="p">(</span><span class="n">value</span><span class="p">))</span>

<span class="c">#===============================================================================</span></div></div>
<div class="viewcode-block" id="DMEditor"><a class="viewcode-back" href="../../ccqw.html#ccqw.degreesWidget.DMEditor">[docs]</a><span class="k">class</span> <span class="nc">DMEditor</span><span class="p">(</span><span class="n">AbstractDEditor</span><span class="p">):</span>
  <span class="sd">&quot;&quot;&quot; Degrees, Minutes Line Editor</span>

<span class="sd">      Will contain float numbers (degrees, minutes ) with the format</span>
<span class="sd">      **[+-]ddd mm.mmmmmm**</span>
<span class="sd">  &quot;&quot;&quot;</span>
<div class="viewcode-block" id="DMEditor.__init__"><a class="viewcode-back" href="../../ccqw.html#ccqw.degreesWidget.DMEditor.__init__">[docs]</a>  <span class="k">def</span> <span class="nf">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">parent</span><span class="p">):</span>
    <span class="sd">&quot;&quot;&quot; Create a new instance of the editor.</span>

<span class="sd">    :param parent: parent widget</span>
<span class="sd">    :type parent: QtGui widget</span>
<span class="sd">    :raises:</span>
<span class="sd">    &quot;&quot;&quot;</span>
    <span class="k">if</span> <span class="n">parent</span><span class="o">.</span><span class="n">latitude</span><span class="p">:</span>
      <span class="bp">self</span><span class="o">.</span><span class="n">regexp</span> <span class="o">=</span> <span class="p">(</span><span class="s">u&quot;[</span><span class="si">%s</span><span class="s">]([0-8][0-9][°][0-5]\d\.\d{6}&#39;|90[°]00\.0{6}&#39;)&quot;</span> <span class="o">%</span>
        <span class="n">parent</span><span class="o">.</span><span class="n">signschr</span><span class="p">)</span>
    <span class="k">else</span><span class="p">:</span>
      <span class="bp">self</span><span class="o">.</span><span class="n">regexp</span> <span class="o">=</span> <span class="p">(</span><span class="s">u&quot;[</span><span class="si">%s</span><span class="s">]((0\d\d|1[0-7]\d)[°][0-5]\d\.\d{4}&#39;|&quot;</span>
        <span class="s">u&quot;180[°]00\.0{6}&#39;)&quot;</span> <span class="o">%</span> <span class="n">parent</span><span class="o">.</span><span class="n">signschr</span><span class="p">)</span>

    <span class="bp">self</span><span class="o">.</span><span class="n">fmt</span> <span class="o">=</span> <span class="s">&quot;</span><span class="si">%%</span><span class="s">s</span><span class="si">%%</span><span class="s">0</span><span class="si">%d</span><span class="s">d</span><span class="si">%s%%</span><span class="s">0</span><span class="si">%d</span><span class="s">.</span><span class="si">%d</span><span class="s">f</span><span class="si">%s</span><span class="s">&quot;</span> <span class="o">%</span> <span class="p">(</span><span class="n">parent</span><span class="o">.</span><span class="n">degreesLen</span><span class="p">,</span> <span class="n">parent</span><span class="o">.</span><span class="n">degchr</span><span class="p">,</span>
      <span class="mi">3</span> <span class="o">+</span> <span class="n">parent</span><span class="o">.</span><span class="n">mdecimals</span><span class="p">,</span> <span class="n">parent</span><span class="o">.</span><span class="n">mdecimals</span><span class="p">,</span> <span class="n">parent</span><span class="o">.</span><span class="n">minchr</span><span class="p">)</span>

    <span class="bp">self</span><span class="o">.</span><span class="n">defaultValue</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">fmt</span> <span class="o">%</span> <span class="p">(</span><span class="n">parent</span><span class="o">.</span><span class="n">signschr</span><span class="p">[</span><span class="mi">0</span><span class="p">],</span> <span class="mf">0.</span><span class="p">,</span> <span class="mf">0.</span><span class="p">)</span>
    <span class="nb">super</span><span class="p">(</span><span class="n">DMEditor</span><span class="p">,</span> <span class="bp">self</span><span class="p">)</span><span class="o">.</span><span class="n">__init__</span><span class="p">(</span><span class="n">parent</span><span class="p">)</span>
</div>
<div class="viewcode-block" id="DMEditor.value"><a class="viewcode-back" href="../../ccqw.html#ccqw.degreesWidget.DMEditor.value">[docs]</a>  <span class="k">def</span> <span class="nf">value</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
    <span class="sd">&quot;&quot;&quot; Return signed widget string value</span>

<span class="sd">    :returns: signed widget string value</span>
<span class="sd">    :rtype: string</span>
<span class="sd">    :raises:</span>
<span class="sd">    &quot;&quot;&quot;</span>
    <span class="n">dl</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">dWidget</span><span class="o">.</span><span class="n">degreesLen</span>
    <span class="n">sign</span><span class="p">,</span> <span class="n">t</span> <span class="o">=</span> <span class="nb">super</span><span class="p">(</span><span class="n">DMEditor</span><span class="p">,</span> <span class="bp">self</span><span class="p">)</span><span class="o">.</span><span class="n">signAndText</span><span class="p">()</span>
    <span class="n">dd</span> <span class="o">=</span> <span class="nb">str</span><span class="p">(</span><span class="n">t</span><span class="p">[</span><span class="mi">1</span><span class="p">:</span> <span class="n">dl</span> <span class="o">+</span> <span class="mi">1</span><span class="p">])</span>
    <span class="n">mm</span> <span class="o">=</span> <span class="nb">str</span><span class="p">(</span><span class="n">t</span><span class="p">[</span><span class="n">dl</span> <span class="o">+</span> <span class="mi">2</span><span class="p">:</span> <span class="o">-</span><span class="mi">1</span><span class="p">])</span>
    <span class="k">return</span> <span class="n">sign</span> <span class="o">+</span> <span class="n">dd</span><span class="p">,</span> <span class="n">mm</span>
</div>
<div class="viewcode-block" id="DMEditor.asString"><a class="viewcode-back" href="../../ccqw.html#ccqw.degreesWidget.DMEditor.asString">[docs]</a>  <span class="k">def</span> <span class="nf">asString</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">value</span><span class="p">):</span>
    <span class="sd">&quot;&quot;&quot; Return value as formatted string</span>

<span class="sd">        Format is embedded into class.</span>

<span class="sd">    :param value: numerical value</span>
<span class="sd">    :type value: float or int</span>
<span class="sd">    :returns: `value` as formatted string</span>
<span class="sd">    :rtype: string</span>
<span class="sd">    :raises:</span>
<span class="sd">    &quot;&quot;&quot;</span>
    <span class="n">decimals</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">dWidget</span><span class="o">.</span><span class="n">mdecimals</span>
    <span class="n">sign</span><span class="p">,</span> <span class="n">degs</span><span class="p">,</span> <span class="n">mins</span> <span class="o">=</span> <span class="n">deg2dm</span><span class="p">(</span><span class="n">value</span><span class="p">,</span> <span class="n">decimals</span><span class="p">)</span>
    <span class="k">if</span> <span class="n">sign</span> <span class="o">&lt;</span> <span class="mi">0</span><span class="p">:</span>
      <span class="n">signchr</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">dWidget</span><span class="o">.</span><span class="n">signschr</span><span class="p">[</span><span class="mi">1</span><span class="p">]</span>
    <span class="k">else</span><span class="p">:</span>
      <span class="n">signchr</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">dWidget</span><span class="o">.</span><span class="n">signschr</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span>
    <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">fmt</span> <span class="o">%</span> <span class="p">(</span><span class="n">signchr</span><span class="p">,</span> <span class="n">degs</span><span class="p">,</span> <span class="n">mins</span><span class="p">)</span>

<span class="c">#===============================================================================</span></div></div>
<div class="viewcode-block" id="DMSEditor"><a class="viewcode-back" href="../../ccqw.html#ccqw.degreesWidget.DMSEditor">[docs]</a><span class="k">class</span> <span class="nc">DMSEditor</span><span class="p">(</span><span class="n">AbstractDEditor</span><span class="p">):</span>
  <span class="sd">&quot;&quot;&quot; Degrees, Minutes, Seconds Line Editor</span>

<span class="sd">      Will contain float numbers (degrees, minutes ) with the format</span>
<span class="sd">      **[+-]ddd mm ss.ssss**</span>
<span class="sd">  &quot;&quot;&quot;</span>
<div class="viewcode-block" id="DMSEditor.__init__"><a class="viewcode-back" href="../../ccqw.html#ccqw.degreesWidget.DMSEditor.__init__">[docs]</a>  <span class="k">def</span> <span class="nf">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">parent</span><span class="p">):</span>
    <span class="sd">&quot;&quot;&quot; Create a new instance of the editor.</span>

<span class="sd">    :param parent: parent widget</span>
<span class="sd">    :type parent: QtGui widget</span>
<span class="sd">    :raises:</span>
<span class="sd">    &quot;&quot;&quot;</span>
    <span class="k">if</span> <span class="n">parent</span><span class="o">.</span><span class="n">latitude</span><span class="p">:</span>
      <span class="bp">self</span><span class="o">.</span><span class="n">regexp</span> <span class="o">=</span> <span class="p">(</span><span class="s">u&quot;[</span><span class="si">%s</span><span class="s">]([0-8][0-9][°][0-5]\d[&#39;][0-5]\d\.\d{4}</span><span class="se">\&quot;</span><span class="s">|&quot;</span>
        <span class="s">u&quot;90[°]00&#39;00\.0{4}</span><span class="se">\&quot;</span><span class="s">)&quot;</span> <span class="o">%</span> <span class="n">parent</span><span class="o">.</span><span class="n">signschr</span><span class="p">)</span>
    <span class="k">else</span><span class="p">:</span>
      <span class="bp">self</span><span class="o">.</span><span class="n">regexp</span> <span class="o">=</span> <span class="p">(</span><span class="s">u&quot;[</span><span class="si">%s</span><span class="s">]((0\d\d|1[0-7]\d)[°][0-5]\d[&#39;][0-5]\d\.\d{4}</span><span class="se">\&quot;</span><span class="s">|&quot;</span>
        <span class="s">u&quot;180[°]00&#39;00\.0{4}</span><span class="se">\&quot;</span><span class="s">)&quot;</span> <span class="o">%</span> <span class="n">parent</span><span class="o">.</span><span class="n">signschr</span><span class="p">)</span>

    <span class="bp">self</span><span class="o">.</span><span class="n">fmt</span> <span class="o">=</span> <span class="s">&quot;</span><span class="si">%%</span><span class="s">s</span><span class="si">%%</span><span class="s">0</span><span class="si">%d</span><span class="s">d</span><span class="si">%s%%</span><span class="s">02d</span><span class="si">%s%%</span><span class="s">0</span><span class="si">%d</span><span class="s">.</span><span class="si">%d</span><span class="s">f</span><span class="si">%s</span><span class="s">&quot;</span> <span class="o">%</span> <span class="p">(</span>
      <span class="n">parent</span><span class="o">.</span><span class="n">degreesLen</span><span class="p">,</span> <span class="n">parent</span><span class="o">.</span><span class="n">degchr</span><span class="p">,</span> <span class="n">parent</span><span class="o">.</span><span class="n">minchr</span><span class="p">,</span>
      <span class="mi">3</span> <span class="o">+</span> <span class="n">parent</span><span class="o">.</span><span class="n">sdecimals</span><span class="p">,</span> <span class="n">parent</span><span class="o">.</span><span class="n">sdecimals</span><span class="p">,</span> <span class="n">parent</span><span class="o">.</span><span class="n">secchr</span><span class="p">)</span>

    <span class="bp">self</span><span class="o">.</span><span class="n">defaultValue</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">fmt</span> <span class="o">%</span> <span class="p">(</span><span class="n">parent</span><span class="o">.</span><span class="n">signschr</span><span class="p">[</span><span class="mi">0</span><span class="p">],</span> <span class="mf">0.</span><span class="p">,</span> <span class="mf">0.</span><span class="p">,</span> <span class="mf">0.</span><span class="p">)</span>
    <span class="nb">super</span><span class="p">(</span><span class="n">DMSEditor</span><span class="p">,</span> <span class="bp">self</span><span class="p">)</span><span class="o">.</span><span class="n">__init__</span><span class="p">(</span><span class="n">parent</span><span class="p">)</span>
</div>
<div class="viewcode-block" id="DMSEditor.value"><a class="viewcode-back" href="../../ccqw.html#ccqw.degreesWidget.DMSEditor.value">[docs]</a>  <span class="k">def</span> <span class="nf">value</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
    <span class="sd">&quot;&quot;&quot; Return signed widget string value</span>

<span class="sd">    :returns: signed widget string value</span>
<span class="sd">    :rtype: string</span>
<span class="sd">    :raises:</span>
<span class="sd">    &quot;&quot;&quot;</span>
    <span class="n">dl</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">dWidget</span><span class="o">.</span><span class="n">degreesLen</span>
    <span class="n">sign</span><span class="p">,</span> <span class="n">t</span> <span class="o">=</span> <span class="nb">super</span><span class="p">(</span><span class="n">DMSEditor</span><span class="p">,</span> <span class="bp">self</span><span class="p">)</span><span class="o">.</span><span class="n">signAndText</span><span class="p">()</span>
    <span class="n">dd</span> <span class="o">=</span> <span class="nb">str</span><span class="p">(</span><span class="n">t</span><span class="p">[</span><span class="mi">1</span><span class="p">:</span> <span class="n">dl</span> <span class="o">+</span> <span class="mi">1</span><span class="p">])</span>
    <span class="n">mm</span> <span class="o">=</span> <span class="nb">str</span><span class="p">(</span><span class="n">t</span><span class="p">[</span><span class="n">dl</span> <span class="o">+</span> <span class="mi">2</span><span class="p">:</span> <span class="n">dl</span> <span class="o">+</span> <span class="mi">4</span><span class="p">])</span>
    <span class="n">ss</span> <span class="o">=</span> <span class="nb">str</span><span class="p">(</span><span class="n">t</span><span class="p">[</span><span class="n">dl</span> <span class="o">+</span> <span class="mi">5</span><span class="p">:</span> <span class="o">-</span><span class="mi">1</span><span class="p">])</span>
    <span class="k">return</span> <span class="n">sign</span> <span class="o">+</span> <span class="n">dd</span><span class="p">,</span> <span class="n">mm</span><span class="p">,</span> <span class="n">ss</span>
</div>
<div class="viewcode-block" id="DMSEditor.asString"><a class="viewcode-back" href="../../ccqw.html#ccqw.degreesWidget.DMSEditor.asString">[docs]</a>  <span class="k">def</span> <span class="nf">asString</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">value</span><span class="p">):</span>
    <span class="sd">&quot;&quot;&quot; Return value as formatted string</span>

<span class="sd">        Format is embedded into class.</span>

<span class="sd">    :param value: numerical value</span>
<span class="sd">    :type value: float or int</span>
<span class="sd">    :returns: `value` as formatted string</span>
<span class="sd">    :rtype: string</span>
<span class="sd">    :raises:</span>
<span class="sd">    &quot;&quot;&quot;</span>
    <span class="n">decimals</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">dWidget</span><span class="o">.</span><span class="n">sdecimals</span>
    <span class="n">sign</span><span class="p">,</span> <span class="n">degs</span><span class="p">,</span> <span class="n">mins</span><span class="p">,</span> <span class="n">secs</span> <span class="o">=</span> <span class="n">deg2dms</span><span class="p">(</span><span class="n">value</span><span class="p">,</span> <span class="n">decimals</span><span class="p">)</span>
    <span class="k">if</span> <span class="n">sign</span> <span class="o">&lt;</span> <span class="mi">0</span><span class="p">:</span>
      <span class="n">signchr</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">dWidget</span><span class="o">.</span><span class="n">signschr</span><span class="p">[</span><span class="mi">1</span><span class="p">]</span>
    <span class="k">else</span><span class="p">:</span>
      <span class="n">signchr</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">dWidget</span><span class="o">.</span><span class="n">signschr</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span>
    <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">fmt</span> <span class="o">%</span> <span class="p">(</span><span class="n">signchr</span><span class="p">,</span> <span class="n">degs</span><span class="p">,</span> <span class="n">mins</span><span class="p">,</span> <span class="n">secs</span><span class="p">)</span>

<span class="c">#===============================================================================</span></div></div>
<div class="viewcode-block" id="DegreesWidget"><a class="viewcode-back" href="../../ccqw.html#ccqw.degreesWidget.DegreesWidget">[docs]</a><span class="k">class</span> <span class="nc">DegreesWidget</span><span class="p">(</span><span class="n">QtGui</span><span class="o">.</span><span class="n">QWidget</span><span class="p">):</span>
  <span class="sd">&quot;&quot;&quot; A Degrees Widget that handles different representations:</span>

<span class="sd">        * Degrees.decimals,</span>
<span class="sd">        * Degrees Minutes.decimals,</span>
<span class="sd">        * Degrees, Minutes, Seconds.decimals</span>
<span class="sd">  &quot;&quot;&quot;</span>
  <span class="n">textEditedSignal</span> <span class="o">=</span> <span class="n">Signal</span><span class="p">(</span><span class="nb">object</span><span class="p">)</span>
  <span class="n">DDD</span> <span class="o">=</span> <span class="mi">0</span>
  <span class="n">DMM</span> <span class="o">=</span> <span class="mi">1</span>
  <span class="n">DMS</span> <span class="o">=</span> <span class="mi">2</span>

<div class="viewcode-block" id="DegreesWidget.__init__"><a class="viewcode-back" href="../../ccqw.html#ccqw.degreesWidget.DegreesWidget.__init__">[docs]</a>  <span class="k">def</span> <span class="nf">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="o">*</span><span class="n">args</span><span class="p">,</span> <span class="o">**</span><span class="n">kargs</span><span class="p">):</span>
    <span class="sd">&quot;&quot;&quot; Create a new instance of the widget.</span>

<span class="sd">        The first argument, if present, is the value to assign.</span>

<span class="sd">        The following keyword arguments are understood:</span>

<span class="sd">        - latitude  : widget will hold latitude [-90, 90] degrees.</span>
<span class="sd">                    Default is True</span>
<span class="sd">        - signstr   : characters identifying sign according to latitude.</span>
<span class="sd">                    Default is &quot;NSEW&quot;</span>
<span class="sd">        - degchr    : character for degrees.</span>
<span class="sd">                    Default is °</span>
<span class="sd">        - minchr    : character for minutes.</span>
<span class="sd">                    Default is &#39;</span>
<span class="sd">        - secchr    : character for seconds.</span>
<span class="sd">                    Default is &quot;</span>
<span class="sd">        - ddecimals : number of decimals for degrees representation.</span>
<span class="sd">                    Default is 9</span>
<span class="sd">        - mdecimals : number of decimals for degrees, minutes.</span>
<span class="sd">                    Default is 6</span>
<span class="sd">        - sdecimals : number of decimals for degrees, minutes, seconds.</span>
<span class="sd">                    Default is 4</span>
<span class="sd">        - rep       : representation to show after creation.</span>
<span class="sd">                    Default is :class:`DDD`</span>
<span class="sd">        - align     : alignment of the widget.</span>
<span class="sd">                    Default is Qt.AlignRight</span>
<span class="sd">        - readonly  : read only attribute.</span>
<span class="sd">                    Default is False</span>
<span class="sd">    &quot;&quot;&quot;</span>

    <span class="k">if</span> <span class="nb">len</span><span class="p">(</span><span class="n">args</span><span class="p">)</span> <span class="o">&gt;</span> <span class="mi">1</span><span class="p">:</span>
      <span class="n">value</span> <span class="o">=</span> <span class="n">args</span><span class="p">[</span><span class="mi">1</span><span class="p">]</span>
    <span class="k">else</span><span class="p">:</span>
      <span class="n">value</span> <span class="o">=</span> <span class="bp">None</span>
    <span class="k">if</span> <span class="nb">len</span><span class="p">(</span><span class="n">args</span><span class="p">)</span> <span class="o">&gt;</span> <span class="mi">0</span><span class="p">:</span>
      <span class="n">parent</span> <span class="o">=</span> <span class="n">args</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span>
    <span class="k">else</span><span class="p">:</span>
      <span class="n">parent</span> <span class="o">=</span> <span class="bp">None</span>
    <span class="nb">super</span><span class="p">(</span><span class="n">DegreesWidget</span><span class="p">,</span> <span class="bp">self</span><span class="p">)</span><span class="o">.</span><span class="n">__init__</span><span class="p">(</span><span class="n">parent</span><span class="p">)</span>

    <span class="bp">self</span><span class="o">.</span><span class="n">latitude</span> <span class="o">=</span> <span class="n">kargs</span><span class="o">.</span><span class="n">pop</span><span class="p">(</span><span class="s">&#39;latitude&#39;</span><span class="p">,</span> <span class="bp">True</span><span class="p">)</span>
    <span class="bp">self</span><span class="o">.</span><span class="n">signstr</span> <span class="o">=</span> <span class="n">kargs</span><span class="o">.</span><span class="n">pop</span><span class="p">(</span><span class="s">&#39;signstr&#39;</span><span class="p">,</span> <span class="s">u&quot;NSEW&quot;</span><span class="p">)</span>
    <span class="bp">self</span><span class="o">.</span><span class="n">degchr</span> <span class="o">=</span> <span class="n">kargs</span><span class="o">.</span><span class="n">pop</span><span class="p">(</span><span class="s">&#39;degchr&#39;</span><span class="p">,</span> <span class="s">u&quot;</span><span class="se">\N{DEGREE SIGN}</span><span class="s">&quot;</span><span class="p">)</span>
    <span class="bp">self</span><span class="o">.</span><span class="n">minchr</span> <span class="o">=</span> <span class="n">kargs</span><span class="o">.</span><span class="n">pop</span><span class="p">(</span><span class="s">&#39;minchr&#39;</span><span class="p">,</span> <span class="s">u&quot;&#39;&quot;</span><span class="p">)</span>
    <span class="bp">self</span><span class="o">.</span><span class="n">secchr</span> <span class="o">=</span> <span class="n">kargs</span><span class="o">.</span><span class="n">pop</span><span class="p">(</span><span class="s">&#39;secchr&#39;</span><span class="p">,</span> <span class="s">u&#39;&quot;&#39;</span><span class="p">)</span>
    <span class="bp">self</span><span class="o">.</span><span class="n">ddecimals</span> <span class="o">=</span> <span class="n">kargs</span><span class="o">.</span><span class="n">pop</span><span class="p">(</span><span class="s">&#39;ddecimals&#39;</span><span class="p">,</span> <span class="mi">9</span><span class="p">)</span>
    <span class="bp">self</span><span class="o">.</span><span class="n">mdecimals</span> <span class="o">=</span> <span class="n">kargs</span><span class="o">.</span><span class="n">pop</span><span class="p">(</span><span class="s">&#39;mdecimals&#39;</span><span class="p">,</span> <span class="mi">6</span><span class="p">)</span>
    <span class="bp">self</span><span class="o">.</span><span class="n">sdecimals</span> <span class="o">=</span> <span class="n">kargs</span><span class="o">.</span><span class="n">pop</span><span class="p">(</span><span class="s">&#39;sdecimals&#39;</span><span class="p">,</span> <span class="mi">4</span><span class="p">)</span>
    <span class="n">rep</span> <span class="o">=</span> <span class="n">kargs</span><span class="o">.</span><span class="n">pop</span><span class="p">(</span><span class="s">&#39;rep&#39;</span><span class="p">,</span> <span class="mi">0</span><span class="p">)</span>
    <span class="bp">self</span><span class="o">.</span><span class="n">align</span> <span class="o">=</span> <span class="n">kargs</span><span class="o">.</span><span class="n">pop</span><span class="p">(</span><span class="s">&#39;align&#39;</span><span class="p">,</span> <span class="n">Qt</span><span class="o">.</span><span class="n">AlignRight</span><span class="p">)</span>
    <span class="n">readonly</span> <span class="o">=</span> <span class="n">kargs</span><span class="o">.</span><span class="n">pop</span><span class="p">(</span><span class="s">&#39;readonly&#39;</span><span class="p">,</span> <span class="bp">False</span><span class="p">)</span>

    <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">latitude</span><span class="p">:</span>
      <span class="bp">self</span><span class="o">.</span><span class="n">signschr</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">signstr</span><span class="p">[:</span><span class="mi">2</span><span class="p">]</span>
      <span class="bp">self</span><span class="o">.</span><span class="n">degreesLen</span> <span class="o">=</span> <span class="mi">2</span>
      <span class="bp">self</span><span class="o">.</span><span class="n">setObjectName</span><span class="p">(</span><span class="n">QCA</span><span class="o">.</span><span class="n">translate</span><span class="p">(</span><span class="s">&quot;degreesWidget&quot;</span><span class="p">,</span> <span class="s">&quot;Latitude&quot;</span><span class="p">))</span>
    <span class="k">else</span><span class="p">:</span>
      <span class="bp">self</span><span class="o">.</span><span class="n">signschr</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">signstr</span><span class="p">[</span><span class="mi">2</span><span class="p">:]</span>
      <span class="bp">self</span><span class="o">.</span><span class="n">degreesLen</span> <span class="o">=</span> <span class="mi">3</span>
      <span class="bp">self</span><span class="o">.</span><span class="n">setObjectName</span><span class="p">(</span><span class="n">QCA</span><span class="o">.</span><span class="n">translate</span><span class="p">(</span><span class="s">&quot;degreesWidget&quot;</span><span class="p">,</span> <span class="s">&quot;Longitude&quot;</span><span class="p">))</span>
    <span class="bp">self</span><span class="o">.</span><span class="n">swidget</span> <span class="o">=</span> <span class="n">QtGui</span><span class="o">.</span><span class="n">QStackedWidget</span><span class="p">()</span>
    <span class="k">for</span> <span class="n">editor</span><span class="p">,</span> <span class="n">toolTip</span> <span class="ow">in</span> <span class="nb">zip</span><span class="p">(</span>
      <span class="p">(</span><span class="n">DEditor</span><span class="p">(</span><span class="bp">self</span><span class="p">),</span> <span class="n">DMEditor</span><span class="p">(</span><span class="bp">self</span><span class="p">),</span> <span class="n">DMSEditor</span><span class="p">(</span><span class="bp">self</span><span class="p">)),</span>
      <span class="p">(</span><span class="n">QCA</span><span class="o">.</span><span class="n">translate</span><span class="p">(</span><span class="s">&quot;degreesWidget&quot;</span><span class="p">,</span>
      <span class="s">&quot;Enter here </span><span class="si">%s</span><span class="s"> in</span><span class="se">\n</span><span class="s">degrees.decimals&quot;</span><span class="p">),</span>
      <span class="n">QCA</span><span class="o">.</span><span class="n">translate</span><span class="p">(</span><span class="s">&quot;degreesWidget&quot;</span><span class="p">,</span>
      <span class="s">&quot;Enter here </span><span class="si">%s</span><span class="s"> in</span><span class="se">\n</span><span class="s">degrees, minutes.decimals&quot;</span><span class="p">),</span>
      <span class="n">QCA</span><span class="o">.</span><span class="n">translate</span><span class="p">(</span><span class="s">&quot;degreesWidget&quot;</span><span class="p">,</span>
      <span class="s">&quot;Enter here </span><span class="si">%s</span><span class="s"> in</span><span class="se">\n</span><span class="s">degrees, minutes, seconds.decimals&quot;</span><span class="p">))):</span>
      <span class="n">editor</span><span class="o">.</span><span class="n">setToolTip</span><span class="p">(</span><span class="n">toolTip</span> <span class="o">%</span> <span class="nb">str</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">objectName</span><span class="p">())</span><span class="o">.</span><span class="n">lower</span><span class="p">())</span>
      <span class="bp">self</span><span class="o">.</span><span class="n">swidget</span><span class="o">.</span><span class="n">addWidget</span><span class="p">(</span><span class="n">editor</span><span class="p">)</span>
      <span class="n">editor</span><span class="o">.</span><span class="n">setReadOnly</span><span class="p">(</span><span class="n">readonly</span><span class="p">)</span>
      <span class="n">editor</span><span class="o">.</span><span class="n">textEdited</span><span class="o">.</span><span class="n">connect</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">textEdited</span><span class="p">)</span>

    <span class="c"># Representation</span>
    <span class="bp">self</span><span class="o">.</span><span class="n">setRep</span><span class="p">(</span><span class="n">rep</span><span class="p">)</span>

    <span class="c"># Layout</span>
    <span class="bp">self</span><span class="o">.</span><span class="n">_layout</span> <span class="o">=</span> <span class="n">QtGui</span><span class="o">.</span><span class="n">QVBoxLayout</span><span class="p">(</span><span class="bp">self</span><span class="p">)</span>
    <span class="bp">self</span><span class="o">.</span><span class="n">_layout</span><span class="o">.</span><span class="n">addWidget</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">swidget</span><span class="p">,</span> <span class="n">alignment</span><span class="o">=</span><span class="n">Qt</span><span class="o">.</span><span class="n">AlignLeft</span><span class="o">|</span><span class="n">Qt</span><span class="o">.</span><span class="n">AlignVCenter</span><span class="p">)</span>
    <span class="bp">self</span><span class="o">.</span><span class="n">_layout</span><span class="o">.</span><span class="n">setContentsMargins</span><span class="p">(</span><span class="mi">0</span><span class="p">,</span> <span class="mi">0</span><span class="p">,</span> <span class="mi">0</span><span class="p">,</span> <span class="mi">0</span><span class="p">)</span>

    <span class="k">if</span> <span class="n">value</span> <span class="ow">is</span> <span class="ow">not</span> <span class="bp">None</span><span class="p">:</span>
      <span class="bp">self</span><span class="o">.</span><span class="n">setValue</span><span class="p">(</span><span class="n">value</span><span class="p">)</span>
</div>
<div class="viewcode-block" id="DegreesWidget.textEdited"><a class="viewcode-back" href="../../ccqw.html#ccqw.degreesWidget.DegreesWidget.textEdited">[docs]</a>  <span class="k">def</span> <span class="nf">textEdited</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">text</span><span class="p">):</span>
    <span class="sd">&quot;&quot;&quot; Update all widgets except the one that sent the signal</span>

<span class="sd">    :param text: the content of the editor widget</span>
<span class="sd">    :type text: string</span>
<span class="sd">    :raises:</span>
<span class="sd">    &quot;&quot;&quot;</span>
    <span class="c"># Update other widgets:</span>
    <span class="k">for</span> <span class="n">i</span> <span class="ow">in</span> <span class="nb">xrange</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">swidget</span><span class="o">.</span><span class="n">count</span><span class="p">()):</span>
      <span class="n">widget</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">swidget</span><span class="o">.</span><span class="n">widget</span><span class="p">(</span><span class="n">i</span><span class="p">)</span>
      <span class="k">if</span> <span class="n">widget</span> <span class="ow">is</span> <span class="ow">not</span> <span class="bp">self</span><span class="o">.</span><span class="n">sender</span><span class="p">():</span>
        <span class="n">widget</span><span class="o">.</span><span class="n">setValue</span><span class="p">(</span><span class="n">dms2deg</span><span class="p">(</span><span class="o">*</span><span class="bp">self</span><span class="o">.</span><span class="n">sender</span><span class="p">()</span><span class="o">.</span><span class="n">fvalue</span><span class="p">()))</span>
    <span class="c"># Send signal with the new value</span>
    <span class="bp">self</span><span class="o">.</span><span class="n">textEditedSignal</span><span class="o">.</span><span class="n">emit</span><span class="p">(</span><span class="n">dms2deg</span><span class="p">(</span><span class="o">*</span><span class="bp">self</span><span class="o">.</span><span class="n">sender</span><span class="p">()</span><span class="o">.</span><span class="n">fvalue</span><span class="p">()))</span>
</div>
<div class="viewcode-block" id="DegreesWidget.setRep"><a class="viewcode-back" href="../../ccqw.html#ccqw.degreesWidget.DegreesWidget.setRep">[docs]</a>  <span class="k">def</span> <span class="nf">setRep</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">rep</span><span class="o">=</span><span class="n">DDD</span><span class="p">):</span>
    <span class="sd">&quot;&quot;&quot; Set widget aspect (representation) according to rep:</span>

<span class="sd">    :param rep: new representation</span>
<span class="sd">    :type rep: any of :class:`DDD`, :class:`DMM`, :class:`DMS`</span>
<span class="sd">    :raises:</span>
<span class="sd">    &quot;&quot;&quot;</span>
    <span class="bp">self</span><span class="o">.</span><span class="n">swidget</span><span class="o">.</span><span class="n">setCurrentIndex</span><span class="p">(</span><span class="n">rep</span><span class="p">)</span>
</div>
<div class="viewcode-block" id="DegreesWidget.fvalue"><a class="viewcode-back" href="../../ccqw.html#ccqw.degreesWidget.DegreesWidget.fvalue">[docs]</a>  <span class="k">def</span> <span class="nf">fvalue</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">rep</span><span class="o">=</span><span class="bp">None</span><span class="p">):</span>
    <span class="sd">&quot;&quot;&quot; Return widget float value(s) according to rep</span>
<span class="sd">        Default is current representation</span>

<span class="sd">    :param rep: representation</span>
<span class="sd">    :type rep: any of :class:`DDD`, :class:`DMM`, :class:`DMS`</span>
<span class="sd">    :returns: widget float value(s) according to rep</span>
<span class="sd">    :rtype: list</span>
<span class="sd">    :raises:</span>
<span class="sd">    &quot;&quot;&quot;</span>
    <span class="k">return</span> <span class="p">[</span><span class="nb">float</span><span class="p">(</span><span class="n">v</span><span class="p">)</span> <span class="k">for</span> <span class="n">v</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">tvalue</span><span class="p">(</span><span class="n">rep</span><span class="p">)]</span>
</div>
<div class="viewcode-block" id="DegreesWidget.tvalue"><a class="viewcode-back" href="../../ccqw.html#ccqw.degreesWidget.DegreesWidget.tvalue">[docs]</a>  <span class="k">def</span> <span class="nf">tvalue</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">rep</span><span class="o">=</span><span class="bp">None</span><span class="p">):</span>
    <span class="sd">&quot;&quot;&quot; Return widget tuple string value according to rep</span>
<span class="sd">        Default is current representation</span>

<span class="sd">    :param rep: representation</span>
<span class="sd">    :type rep: any of :class:`DDD`, :class:`DMM`, :class:`DMS`</span>
<span class="sd">    :returns: widget tuple string value according to rep</span>
<span class="sd">    :rtype: tuple</span>
<span class="sd">    :raises:</span>
<span class="sd">    &quot;&quot;&quot;</span>
    <span class="k">if</span> <span class="n">rep</span> <span class="ow">is</span> <span class="bp">None</span><span class="p">:</span>
      <span class="n">rep</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">swidget</span><span class="o">.</span><span class="n">currentIndex</span><span class="p">()</span>

    <span class="c"># All editors have the same value</span>
    <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">swidget</span><span class="o">.</span><span class="n">widget</span><span class="p">(</span><span class="n">rep</span><span class="p">)</span><span class="o">.</span><span class="n">value</span><span class="p">()</span>
</div>
<div class="viewcode-block" id="DegreesWidget.svalue"><a class="viewcode-back" href="../../ccqw.html#ccqw.degreesWidget.DegreesWidget.svalue">[docs]</a>  <span class="k">def</span> <span class="nf">svalue</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">rep</span><span class="o">=</span><span class="bp">None</span><span class="p">):</span>
    <span class="sd">&quot;&quot;&quot; Return widget string value according to rep</span>

<span class="sd">        Default is current representation</span>

<span class="sd">    :param rep: representation</span>
<span class="sd">    :type rep: any of :class:`DDD`, :class:`DMM`, :class:`DMS`</span>
<span class="sd">    :returns: widget string value according to rep</span>
<span class="sd">    :rtype: tuple</span>
<span class="sd">    :raises:</span>
<span class="sd">    &quot;&quot;&quot;</span>
    <span class="k">if</span> <span class="n">rep</span> <span class="ow">is</span> <span class="bp">None</span><span class="p">:</span>
      <span class="n">rep</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">rep</span><span class="p">()</span>

    <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">swidget</span><span class="o">.</span><span class="n">widget</span><span class="p">(</span><span class="n">rep</span><span class="p">)</span><span class="o">.</span><span class="n">svalue</span><span class="p">()</span>
</div>
<div class="viewcode-block" id="DegreesWidget.setValue"><a class="viewcode-back" href="../../ccqw.html#ccqw.degreesWidget.DegreesWidget.setValue">[docs]</a>  <span class="k">def</span> <span class="nf">setValue</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="o">*</span><span class="n">values</span><span class="p">):</span>
    <span class="sd">&quot;&quot;&quot; Set widget value.</span>

<span class="sd">      :param \*values: either degs *OR* (degs mins) *OR* (degs, mins, secs)</span>
<span class="sd">      :type \*values: float or tuple of floats</span>
<span class="sd">      :raises:</span>
<span class="sd">    &quot;&quot;&quot;</span>
    <span class="n">degrees</span> <span class="o">=</span> <span class="n">dms2deg</span><span class="p">(</span><span class="o">*</span><span class="n">values</span><span class="p">)</span>

    <span class="c"># Set value to all widgets</span>
    <span class="k">for</span> <span class="n">i</span> <span class="ow">in</span> <span class="nb">xrange</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">swidget</span><span class="o">.</span><span class="n">count</span><span class="p">()):</span>
      <span class="bp">self</span><span class="o">.</span><span class="n">swidget</span><span class="o">.</span><span class="n">widget</span><span class="p">(</span><span class="n">i</span><span class="p">)</span><span class="o">.</span><span class="n">setValue</span><span class="p">(</span><span class="n">degrees</span><span class="p">)</span>
</div>
<div class="viewcode-block" id="DegreesWidget.rep"><a class="viewcode-back" href="../../ccqw.html#ccqw.degreesWidget.DegreesWidget.rep">[docs]</a>  <span class="k">def</span> <span class="nf">rep</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
    <span class="sd">&quot;&quot;&quot; Return current representation</span>

<span class="sd">    :returns: widget current representation</span>
<span class="sd">    :rtype: int</span>
<span class="sd">    :raises:</span>
<span class="sd">    &quot;&quot;&quot;</span>
    <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">swidget</span><span class="o">.</span><span class="n">currentIndex</span><span class="p">()</span>
</div></div>
<span class="k">if</span> <span class="n">__name__</span> <span class="o">==</span> <span class="s">&#39;__main__&#39;</span><span class="p">:</span>
  <span class="kn">import</span> <span class="nn">sys</span>
  <span class="kn">from</span> <span class="nn">signal</span> <span class="kn">import</span> <span class="n">signal</span><span class="p">,</span> <span class="n">SIGINT</span><span class="p">,</span> <span class="n">SIG_DFL</span>

  <span class="n">signal</span><span class="p">(</span><span class="n">SIGINT</span><span class="p">,</span> <span class="n">SIG_DFL</span><span class="p">)</span>
  <span class="n">app</span> <span class="o">=</span> <span class="n">QtGui</span><span class="o">.</span><span class="n">QApplication</span><span class="p">(</span><span class="n">sys</span><span class="o">.</span><span class="n">argv</span><span class="p">)</span>
  <span class="n">w</span> <span class="o">=</span> <span class="n">DegreesWidget</span><span class="p">(</span><span class="bp">None</span><span class="p">,</span> <span class="n">latitude</span><span class="o">=</span><span class="bp">False</span><span class="p">,</span> <span class="n">rep</span><span class="o">=</span><span class="n">DegreesWidget</span><span class="o">.</span><span class="n">DMS</span><span class="p">)</span>
  <span class="n">w</span><span class="o">.</span><span class="n">setValue</span><span class="p">(</span><span class="o">-</span><span class="mi">123</span><span class="p">,</span> <span class="mi">45</span><span class="p">,</span> <span class="mi">54</span><span class="p">)</span>
  <span class="n">w</span><span class="o">.</span><span class="n">show</span><span class="p">()</span>
  <span class="n">sys</span><span class="o">.</span><span class="n">exit</span><span class="p">(</span><span class="n">app</span><span class="o">.</span><span class="n">exec_</span><span class="p">())</span>
</pre></div>

          </div>
        </div>
      </div>
      <div class="sphinxsidebar">
        <div class="sphinxsidebarwrapper">
            <p class="logo"><a href="../../index.html">
              <img class="logo" src="../../_static/ogs.png" alt="Logo"/>
            </a></p>
<div id="searchbox" style="display: none">
  <h3>Quick search</h3>
    <form class="search" action="../../search.html" method="get">
      <input type="text" name="q" />
      <input type="submit" value="Go" />
      <input type="hidden" name="check_keywords" value="yes" />
      <input type="hidden" name="area" value="default" />
    </form>
    <p class="searchtip" style="font-size: 90%">
    Enter search terms or a module, class or function name.
    </p>
</div>
<script type="text/javascript">$('#searchbox').show(0);</script>
        </div>
      </div>
      <div class="clearer"></div>
    </div>
    <div class="related">
      <h3>Navigation</h3>
      <ul>
        <li class="right" style="margin-right: 10px">
          <a href="../../genindex.html" title="General Index"
             >index</a></li>
        <li class="right" >
          <a href="../../py-modindex.html" title="Python Module Index"
             >modules</a> |</li>
        <li><a href="../../index.html">CCQW 0.1.1 documentation</a> &raquo;</li>
          <li><a href="../index.html" >Module code</a> &raquo;</li> 
      </ul>
    </div>
    <div class="footer">
        &copy; Copyright 2012, Roberto Vidmar, Nicola Creati.
      Created using <a href="http://sphinx.pocoo.org/">Sphinx</a> 1.1.3.
    </div>
  </body>
</html>